﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region CMS_Article实体类
public class CMS_Article
{
	private string m_ArticleID;
	private string m_ArticleTitle;
	private string m_ArticleType;
	private string m_ArticleContent;
	private string m_TemplateID;
	private string m_ColumnID;
	private int m_IsDefault;
	private string m_SequenceNo;
	private DateTime m_CreateTime;
	private string m_CreateBy;
	private int m_Disabled;
	private string m_Tag;
	
	public CMS_Article ()
	{
		m_ArticleID="";
		m_ArticleTitle="";
		m_ArticleType="";
		m_ArticleContent="";
		m_TemplateID="";
		m_ColumnID="";
		m_IsDefault=0;
		m_SequenceNo="";
		m_CreateTime=DateTime.Now;
		m_CreateBy="";
		m_Disabled=0;
		m_Tag="";
	}
	
	public string ArticleID
	{
		get{return m_ArticleID;}
		set{m_ArticleID=value;}
	}
	public string ArticleTitle
	{
		get{return m_ArticleTitle;}
		set{m_ArticleTitle=value;}
	}
	public string ArticleType
	{
		get{return m_ArticleType;}
		set{m_ArticleType=value;}
	}
	public string ArticleContent
	{
		get{return m_ArticleContent;}
		set{m_ArticleContent=value;}
	}
	public string TemplateID
	{
		get{return m_TemplateID;}
		set{m_TemplateID=value;}
	}
	public string ColumnID
	{
		get{return m_ColumnID;}
		set{m_ColumnID=value;}
	}
	public int IsDefault
	{
		get{return m_IsDefault;}
		set{m_IsDefault=value;}
	}
	public string SequenceNo
	{
		get{return m_SequenceNo;}
		set{m_SequenceNo=value;}
	}
	public DateTime CreateTime
	{
		get{return m_CreateTime;}
		set{m_CreateTime=value;}
	}
	public string CreateBy
	{
		get{return m_CreateBy;}
		set{m_CreateBy=value;}
	}
	public int Disabled
	{
		get{return m_Disabled;}
		set{m_Disabled=value;}
	}
	public string Tag
	{
		get{return m_Tag;}
		set{m_Tag=value;}
	}
}
#endregion

#region CMS_Article管理类
public partial class LogicLayer
{
	public bool AddCMS_Article(CMS_Article theCMS_Article)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into CMS_Article (ArticleID,ArticleTitle,ArticleType,ArticleContent,TemplateID,ColumnID,IsDefault,SequenceNo,CreateTime,CreateBy,Disabled,Tag) values (@ArticleID,@ArticleTitle,@ArticleType,@ArticleContent,@TemplateID,@ColumnID,@IsDefault,@SequenceNo,@CreateTime,@CreateBy,@Disabled,@Tag)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@ArticleID", DbType.String, theCMS_Article.ArticleID);
			db.AddInParameter(cmd, "@ArticleTitle", DbType.String, theCMS_Article.ArticleTitle);
			db.AddInParameter(cmd, "@ArticleType", DbType.String, theCMS_Article.ArticleType);
			db.AddInParameter(cmd, "@ArticleContent", DbType.String, theCMS_Article.ArticleContent);
			db.AddInParameter(cmd, "@TemplateID", DbType.String, theCMS_Article.TemplateID);
			db.AddInParameter(cmd, "@ColumnID", DbType.String, theCMS_Article.ColumnID);
			db.AddInParameter(cmd, "@IsDefault", DbType.Int32, theCMS_Article.IsDefault);
			db.AddInParameter(cmd, "@SequenceNo", DbType.String, theCMS_Article.SequenceNo);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theCMS_Article.CreateTime);
			db.AddInParameter(cmd, "@CreateBy", DbType.String, theCMS_Article.CreateBy);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theCMS_Article.Disabled);
			db.AddInParameter(cmd, "@Tag", DbType.String, theCMS_Article.Tag);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddCMS_Article:" + ex.Message );
			return false;
		}
	}
	
	public CMS_Article GetCMS_ArticleFromDataReader(IDataReader dataReader)
	{
		try
		{
			CMS_Article result = new CMS_Article();
			
			if (dataReader["ArticleID"] != null && dataReader["ArticleID"] != System.DBNull.Value )
				result.ArticleID = (string)dataReader["ArticleID"];
			if (dataReader["ArticleTitle"] != null && dataReader["ArticleTitle"] != System.DBNull.Value )
				result.ArticleTitle = (string)dataReader["ArticleTitle"];
			if (dataReader["ArticleType"] != null && dataReader["ArticleType"] != System.DBNull.Value )
				result.ArticleType = (string)dataReader["ArticleType"];
			if (dataReader["ArticleContent"] != null && dataReader["ArticleContent"] != System.DBNull.Value )
				result.ArticleContent = (string)dataReader["ArticleContent"];
			if (dataReader["TemplateID"] != null && dataReader["TemplateID"] != System.DBNull.Value )
				result.TemplateID = (string)dataReader["TemplateID"];
			if (dataReader["ColumnID"] != null && dataReader["ColumnID"] != System.DBNull.Value )
				result.ColumnID = (string)dataReader["ColumnID"];
			if (dataReader["IsDefault"] != null && dataReader["IsDefault"] != System.DBNull.Value )
				result.IsDefault = (int)dataReader["IsDefault"];
			if (dataReader["SequenceNo"] != null && dataReader["SequenceNo"] != System.DBNull.Value )
				result.SequenceNo = (string)dataReader["SequenceNo"];
			if (dataReader["CreateTime"] != null && dataReader["CreateTime"] != System.DBNull.Value )
				result.CreateTime = (DateTime)dataReader["CreateTime"];
			if (dataReader["CreateBy"] != null && dataReader["CreateBy"] != System.DBNull.Value )
				result.CreateBy = (string)dataReader["CreateBy"];
			if (dataReader["Disabled"] != null && dataReader["Disabled"] != System.DBNull.Value )
				result.Disabled = (int)dataReader["Disabled"];
			if (dataReader["Tag"] != null && dataReader["Tag"] != System.DBNull.Value )
				result.Tag = (string)dataReader["Tag"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderCMS_Article:" + ex.Message);
			return null;
		}
	}
	
	public CMS_Article GetCMS_Article(string ArticleID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From CMS_Article where ArticleID=@ArticleID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@ArticleID", DbType.String, ArticleID);
			
			CMS_Article result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetCMS_ArticleFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetCMS_Article:" + ex.Message);
			return null;
		}
	}
	
	public bool DelCMS_Article(string ArticleID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From CMS_Article where ArticleID=@ArticleID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@ArticleID", DbType.String, ArticleID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelCMS_Article:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateCMS_Article(CMS_Article theCMS_Article)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update CMS_Article set ArticleTitle=@ArticleTitle,ArticleType=@ArticleType,ArticleContent=@ArticleContent,TemplateID=@TemplateID,ColumnID=@ColumnID,IsDefault=@IsDefault,SequenceNo=@SequenceNo,CreateTime=@CreateTime,CreateBy=@CreateBy,Disabled=@Disabled,Tag=@Tag where ArticleID=@ArticleID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@ArticleTitle", DbType.String, theCMS_Article.ArticleTitle);
			db.AddInParameter(cmd, "@ArticleType", DbType.String, theCMS_Article.ArticleType);
			db.AddInParameter(cmd, "@ArticleContent", DbType.String, theCMS_Article.ArticleContent);
			db.AddInParameter(cmd, "@TemplateID", DbType.String, theCMS_Article.TemplateID);
			db.AddInParameter(cmd, "@ColumnID", DbType.String, theCMS_Article.ColumnID);
			db.AddInParameter(cmd, "@IsDefault", DbType.Int32, theCMS_Article.IsDefault);
			db.AddInParameter(cmd, "@SequenceNo", DbType.String, theCMS_Article.SequenceNo);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theCMS_Article.CreateTime);
			db.AddInParameter(cmd, "@CreateBy", DbType.String, theCMS_Article.CreateBy);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theCMS_Article.Disabled);
			db.AddInParameter(cmd, "@Tag", DbType.String, theCMS_Article.Tag);
			db.AddInParameter(cmd, "@ArticleID", DbType.String, theCMS_Article.ArticleID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateCMS_Article:" + ex.Message);
			return false;
		}
	}
	
	public List<CMS_Article> ListCMS_Article()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from CMS_Article";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<CMS_Article> result = new  List<CMS_Article>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					CMS_Article obj = GetCMS_ArticleFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListCMS_Article:" + ex.Message);
			return null;
		}
	}
	
}
#endregion